import 'dart:io';

import 'package:flutter/services.dart';
import 'package:path_provider/path_provider.dart';

class Utils {

  static Future<String> getAbsolutePath(String assetPath) async {

    final Directory tempDir = await getTemporaryDirectory();
    final String tempPath = tempDir.path;

    final String filename = assetPath.split('/').last;
    final String localPath = '$tempPath/$filename';

    try {
      final ByteData data = await rootBundle.load(assetPath);
      final File file = File(localPath);
      await file.writeAsBytes(data.buffer.asUint8List());
      return localPath;
    } catch (e) {
      throw Exception('Failed to copy asset: $assetPath, error: $e');
    }
  }
}